#include "Ghost.h"


Ghost::Ghost(time_t* seedMove)
	:Character			(GHOST, 100)//mLoopToRespawn = 30?
	,mLoopsToNormal		(0)
	,mLoopsSpecialEff	(60)
{
	this->mImage		= new Bitmap("data\\ghost\\inky.tga");
	this->mSpecImage	= new Bitmap("data\\ghost\\ghost_e.tga");
	this->mMoveBehavior = new Wandering(*seedMove);
}
Ghost::Ghost(void)
	:Character			(GHOST, 100)//mLoopToRespawn = 30?
	,mLoopsToNormal		(0)
	,mLoopsSpecialEff	(60)
{
	this->mImage		= new Bitmap("data\\ghost\\inky.tga");
	this->mSpecImage	= new Bitmap("data\\ghost\\ghost_e.tga");
	this->mMoveBehavior = new Wandering();
}
Ghost::Ghost(InputController* nInputCtrl)
	:Character			(GHOST, 100)//mLoopToRespawn = 30?
	,mLoopsToNormal		(0)
	,mLoopsSpecialEff	(60)
{
	this->mImage		= new Bitmap("data\\ghost\\inky.tga");
	this->mSpecImage	= new Bitmap("data\\ghost\\ghost_e.tga");
	this->mMoveBehavior = nInputCtrl;
}

Ghost::~Ghost(void)
{
	delete mImage;
	delete mSpecImage;
}

void Ghost::activate()
{
	Character::activate();
	mCurrentTile->occupiedByGhost = true;
	mMoveBehavior->reset();
}
void Ghost::move(Background* bg)
{
	mMoveBehavior->perform(this, bg);
}
void Ghost::moveTo(const Background* bg, BackgroundElement* nTile)
{
	if(nTile->isWalkable() && nTile->occupiedByGhost == false)
	{
		bg->getTile(mTileIndex)->occupiedByGhost = false;
		Character::moveTo(bg, nTile);
	}
}

void Ghost::setupProximity(const Background* bg, BackgroundElement* tile)
{
	tile->occupiedByGhost = true;
	Character::setupProximity(bg, tile);
}

void Ghost::collisionWith(GameEntity* entity, bool specialActive)
{
	if(entity->isAPacMan())
	{
		if(specialActive)
		{
			deactivate();
			mRemainLoops = mLoopToRespawn;
		}
	}
}

void Ghost::deactivate()
{
	mCurrentTile->occupiedByGhost = false;
	if(this->mActive) 
		this->mActive = false;
}